<?php
namespace app\models;
use yii\base\Model;

class DealLogSearch extends DealLog
{
    public $begin_time;
    public $end_time;

    public function rules()
    {
        return [
            ['way', 'integer', 'message' => 'way必须为数字，或数字字符串'],
            ['way', 'in', 'range' => array(0, 1, 2), 'message' => 'way值必须在0~5中选择'],
            ['begin_time', 'date', 'format'=>'yyyy-MM-dd', 'message' => 'begin_time非yyyy-MM-dd格式'],
            ['end_time', 'date', 'format'=>'yyyy-MM-dd', 'message' => 'end_time非yyyy-MM-dd格式'],

        ];
    }

    public function scenarios()
    {
        return Model::scenarios();
    }

    public function search($params)
    {
        $data['DealLogSearch'] = $params;
        // P($data);

        $query = DealLog::find();

        if (!($this->load($data) && $this->validate())) {
            // if($this->hasErrors()){
            //     P($this->getErrors());
            // }
            return false;
        }
        // P($this);

        if(isset($this->way) and $this->way != 0){
            $query -> andFilterWhere([
                'way' => $this->way,
            ]);
        }

        if(isset($this->end_time) and !empty($this->end_time)){
            $this->end_time .= ' 23:59:59';
        }
        $query -> andFilterWhere(['>=', '{{%pj8_deal_log}}.add_time', $this->begin_time])
               -> andFilterWhere(['<=', '{{%pj8_deal_log}}.add_time', $this->end_time]);

        // P($query);
        return $query;
    }

    
}